
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CustomButton from "../../BASE/CButton";
import ComponentBase from "../../BASE/ComponentBase";
import { gif } from "../../BASE/spineANDgif/gif";
import GeZiManager from "../../Manager/GeZiManager";
import TorW from "./TorW";




const {ccclass, property} = cc._decorator;

@ccclass
export default class moveUI extends ComponentBase {

n:number=0
@property(cc.Node)
d2:cc.Node=null
@property(cc.Node)
d4:cc.Node=null
@property(cc.Node)
d6:cc.Node=null
@property(cc.Node)
d8:cc.Node=null
@property(cc.Node)
d5:cc.Node=null

//初始
    Pri(){
      for(let a of this.node.children){
        a.active=false;
    }
this.node.getChildByName("Background").active=true;
    }
  
    //
    bi(){
  if(this.n=1){
  


this.node.children[0].getComponent(gif).changeF(7,1)
this.d2.active=false
this.d4.active=false
this.d6.active=false
this.d8.active=false
this.d5.active=false;
this.node.getComponent(CustomButton).enableButton();




  }
}
  
  
  
  kai(){
   
  
    for(let a of this.node.parent.children){a.getComponent(CustomButton).toN()}
 
    this.node.children[0].getComponent(gif).changeF(8,1) 
   
    this.d2.active=true
    this.d4.active=true
    this.d6.active=true
    this.d8.active=true
    this.d5.active=true;
           

GeZiManager.PCP.UIC();
this.node.getComponent(CustomButton).disableButton()


}
          

    


torock(nk:number){
 this.TX(nk,"推石头")
    
  
        
                  
}



TX(n:number, a:string) {
  let node: cc.Node;
  switch (n) {
    case 2:
      node = this.d2.children[0];
      break;
    case 4:
      node = this.d4.children[0];
      break;
    case 6:
      node = this.d6.children[0];
      break;
    case 8:
      node = this.d8.children[0];
      break;
    default:
      return;
  }
  

  node.parent.getComponent(TorW).n=a; 
  node.children[1].scaleX=Math.abs(node.children[1].scaleX)
  node.children[1].getComponent(gif).scX=Math.abs(node.children[1].getComponent(gif).scX)
  switch (a) {
    case "推石头":
      node.parent.getComponent(CustomButton).enableButton();node.children[1].getComponent(gif).changeF(1,1)
      node.parent.children[1].getComponent(gif).changeF(this.getTNC(1),1);console.log(this.getTNC(0)-1)
      break;
    case "turn6":
      node.parent.getComponent(CustomButton).enableButton();node.children[1].getComponent(gif).changeF(2,1);
      node.parent.children[1].getComponent(gif).changeF(this.getTNC(0)-1,1);console.log(this.getTNC(0)-1)
      break;
    case "turn4":
      node.parent.getComponent(CustomButton).enableButton();node.children[1].getComponent(gif).changeF(2,1); node.children[1].getComponent(gif).scX=-1;
      node.parent.children[1].getComponent(gif).changeF(this.getTNC(0)-1,1);console.log(this.getTNC(0)-1)
      break;
    case "walk":
      node.parent.getComponent(CustomButton).enableButton();node.children[1].getComponent(gif).changeF(0,1)
      node.parent.children[1].getComponent(gif).changeF(this.getTNC(1)-1,1);console.log(this.getTNC(0)-1)
      break;
      break;
    case "BAN":
      node.parent.getComponent(CustomButton).disableButton();node.children[1].getComponent(gif).changeF(4,1)
      node.parent.children[1].getComponent(gif).changeF(-1,1);console.log(this.getTNC(0)-1)
      break;
    
      case "walk8":
        node.parent.getComponent(CustomButton).enableButton();node.children[1].getComponent(gif).changeF(0,1)
        node.parent.children[1].getComponent(gif).changeF(this.getTNC(1)-1,1);console.log(this.getTNC(0)-1)
    break;
    
      default:
      return;
 
 
    }



  node.children[1].scaleX*=node.children[1].getComponent(gif).scX
}


BAN(a:string){
console.log(a)
  if(this.d2.getComponent(TorW).n==a){this.d2.getComponent(CustomButton).disableButton();}
  if(this.d4.getComponent(TorW).n==a){this.d4.getComponent(CustomButton).disableButton();}
  if(this.d6.getComponent(TorW).n==a){this.d6.getComponent(CustomButton).disableButton();}
  if(this.d8.getComponent(TorW).n==a){this.d8.getComponent(CustomButton).disableButton();}
}


USE(a:string){

  //console.log(a)
    if(this.d2.getComponent(TorW).n==a){this.d2.getComponent(CustomButton).enableButton();}
    if(this.d4.getComponent(TorW).n==a){this.d4.getComponent(CustomButton).enableButton();}
    if(this.d6.getComponent(TorW).n==a){this.d6.getComponent(CustomButton).enableButton();}
    if(this.d8.getComponent(TorW).n==a){this.d8.getComponent(CustomButton).enableButton();}


    
}
getTNC(n:number){


  let k=  GeZiManager.PCP.TNJJ
  let l =GeZiManager.TNC
 if(k[n]+l[n]>=0){return k[n]+l[n]}else {return 0}
 }
 
}
